package com.catmiao.rdd.operate.transform;

import com.google.common.collect.Lists;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

import java.util.ArrayList;

/**
 * @author ChengMiao
 * @title: Transfer_01_Map
 * @projectName spark_study
 * @description: TODO
 * @date 2024/11/25 16:27
 */
public class Transfer_08_distinct {

    public static void main(String[] args) throws InterruptedException {

        final SparkConf conf = new SparkConf();
        conf.setAppName("appName");
        conf.setMaster("local[*]");

        final JavaSparkContext jsc = new JavaSparkContext(conf);


        ArrayList<Integer> list = Lists.newArrayList(1, 2,  3, 4,4);

        JavaRDD<Integer> rdd = jsc.parallelize(list, 3);


        /**
         * distinct：去重
         *      - 分布式去重，采用了分组+shuffle的处理方式
         */
        rdd.distinct().collect().forEach(System.out::println);



        jsc.close();
    }
}
